#pragma once

#ifndef GLOBE_H
#define GLOBE_H

#include "glhead.h"
#include "mtxlib.h"
#include "vector2d.h"
#include <math.h>
#include <vector>

#define P_MODE_DONE 1
#define P_MODE_DOING 2
#define P_MODE_TO_DO 3
#define P_MODE_TEST 4

using std::vector;

typedef struct rec_point
{
	double lg;
	double lt;
	double x;
	double y;
} rec_point;

class globe
{
private:
	int cur_tex;
	float radius;
	float precision;
	bool line;
	int line_display_list;
	int globe_display_list;

	int cur_p;
	double cur_p_percent;

	vector<double> logs;
	vector<double> lats;
	vector<rec_point> calib_points;
	
	float rotate_matrix[16];

	void draw_longitude(double log,int prec);
	void draw_latitude(double lat,int prec);
	void render_lglt(void);
	void render_points(void);
	void create_globe(void);
	void set_texture_coord(float x, float y);
	void write_to_file(const char* file);

public:
	vector2dd cur_point;
	globe(void);
	void draw_point(double log,double lat,int mode,double percentile);
	bool next_rp(double x,double y);
	void init_default_lglt(void);
	void init_lglt_from_file(const char* filename);
	void rotate(vector3 src,vector3 des);
	void render(void);
	~globe(void);

	void set_cur_p_percent(double d){ cur_p_percent = d;}
};

#endif